﻿using System;
using System.ComponentModel;
using System.Runtime.InteropServices;

namespace Teigha.Core
{
	public class OdGeCurveBoundary : IDisposable
	{
		[EditorBrowsable(EditorBrowsableState.Never)]
		public OdGeCurveBoundary(IntPtr cPtr, bool cMemoryOwn)
		{
			this.swigCMemOwn = cMemoryOwn;
			this.swigCPtr = new HandleRef(this, cPtr);
		}

		[EditorBrowsable(EditorBrowsableState.Never)]
		public static HandleRef getCPtr(OdGeCurveBoundary obj)
		{
			if (obj != null)
			{
				return obj.swigCPtr;
			}
			return new HandleRef(null, IntPtr.Zero);
		}

		~OdGeCurveBoundary()
		{
			this.Dispose();
		}

		public virtual void Dispose()
		{
			if (this.swigCPtr.Handle != IntPtr.Zero)
			{
				if (this.swigCMemOwn)
				{
					lock (this.locker)
					{
						if (this.swigCPtr.Handle != IntPtr.Zero && this.swigCMemOwn)
						{
							this.swigCMemOwn = false;
							GlobalsPINVOKE.delete_OdGeCurveBoundary(this.swigCPtr);
						}
					}
					this.swigCMemOwn = false;
				}
				this.swigCPtr = new HandleRef(null, IntPtr.Zero);
			}
			GC.SuppressFinalize(this);
		}

		public void getContour(out int numCurves, out OdGeEntity3d[] crv3d, out OdGeCurve2d[] crv2d, out bool[] orientation3d, out bool[] orientation2d)
		{
			HandleRef handleRef;
			HandleRef handleRef2;
			IntPtr arr;
			IntPtr arr2;
			GlobalsPINVOKE.OdGeCurveBoundary_getContour(this.swigCPtr, out numCurves, out handleRef, out handleRef2, out arr, out arr2);
			if (GlobalsPINVOKE.SWIGPendingException.Pending)
			{
				throw GlobalsPINVOKE.SWIGPendingException.Retrieve();
			}
			crv3d = new OdGeEntity3d[numCurves];
			crv2d = new OdGeCurve2d[numCurves];
			for (int i = 0; i < numCurves; i++)
			{
				crv3d[i] = new OdGeEntity3d(Marshal.ReadIntPtr(handleRef, i * Marshal.SizeOf(Marshal.SizeOf(typeof(IntPtr)))), false);
				crv2d[i] = new OdGeCurve2d(Marshal.ReadIntPtr(handleRef2, i * Marshal.SizeOf(Marshal.SizeOf(typeof(IntPtr)))), false);
			}
			orientation3d = Helpers.UnMarshalBoolFixedArray(arr, numCurves);
			orientation2d = Helpers.UnMarshalBoolFixedArray(arr2, numCurves);
		}

		public OdGeCurveBoundary() : this(GlobalsPINVOKE.new_OdGeCurveBoundary__SWIG_0(), true)
		{
			if (GlobalsPINVOKE.SWIGPendingException.Pending)
			{
				throw GlobalsPINVOKE.SWIGPendingException.Retrieve();
			}
		}

		public OdGeCurveBoundary(int numCurves, OdGeEntity3d[] crv3d, OdGeCurve2d[] crv2d, bool[] orientation3d, bool[] orientation2d, bool makeCopy) : this(GlobalsPINVOKE.new_OdGeCurveBoundary__SWIG_1(numCurves, crv3d, crv2d, Helpers.MarshalboolFixedArray(orientation3d), Helpers.MarshalboolFixedArray(orientation2d), makeCopy), true)
		{
			if (GlobalsPINVOKE.SWIGPendingException.Pending)
			{
				throw GlobalsPINVOKE.SWIGPendingException.Retrieve();
			}
		}

		public OdGeCurveBoundary(int numCurves, OdGeEntity3d[] crv3d, OdGeCurve2d[] crv2d, bool[] orientation3d, bool[] orientation2d) : this(GlobalsPINVOKE.new_OdGeCurveBoundary__SWIG_2(numCurves, crv3d, crv2d, Helpers.MarshalboolFixedArray(orientation3d), Helpers.MarshalboolFixedArray(orientation2d)), true)
		{
			if (GlobalsPINVOKE.SWIGPendingException.Pending)
			{
				throw GlobalsPINVOKE.SWIGPendingException.Retrieve();
			}
		}

		public OdGeCurveBoundary(OdGeCurveBoundary source) : this(GlobalsPINVOKE.new_OdGeCurveBoundary__SWIG_3(OdGeCurveBoundary.getCPtr(source)), true)
		{
			if (GlobalsPINVOKE.SWIGPendingException.Pending)
			{
				throw GlobalsPINVOKE.SWIGPendingException.Retrieve();
			}
		}

		public OdGeCurveBoundary Assign(OdGeCurveBoundary crvBoundary)
		{
			OdGeCurveBoundary result = new OdGeCurveBoundary(GlobalsPINVOKE.OdGeCurveBoundary_Assign(this.swigCPtr, OdGeCurveBoundary.getCPtr(crvBoundary)), false);
			if (GlobalsPINVOKE.SWIGPendingException.Pending)
			{
				throw GlobalsPINVOKE.SWIGPendingException.Retrieve();
			}
			return result;
		}

		public bool isDegenerate()
		{
			bool result = GlobalsPINVOKE.OdGeCurveBoundary_isDegenerate__SWIG_0(this.swigCPtr);
			if (GlobalsPINVOKE.SWIGPendingException.Pending)
			{
				throw GlobalsPINVOKE.SWIGPendingException.Retrieve();
			}
			return result;
		}

		public bool isDegenerate(OdGePosition3d degenPoint, OdGeCurve2d[] paramCurve)
		{
			bool result = GlobalsPINVOKE.OdGeCurveBoundary_isDegenerate__SWIG_1(this.swigCPtr, OdGePosition3d.getCPtr(degenPoint), paramCurve);
			if (GlobalsPINVOKE.SWIGPendingException.Pending)
			{
				throw GlobalsPINVOKE.SWIGPendingException.Retrieve();
			}
			return result;
		}

		public int numElements()
		{
			int result = GlobalsPINVOKE.OdGeCurveBoundary_numElements(this.swigCPtr);
			if (GlobalsPINVOKE.SWIGPendingException.Pending)
			{
				throw GlobalsPINVOKE.SWIGPendingException.Retrieve();
			}
			return result;
		}

		public OdGeCurveBoundary set(int numCurves, OdGeEntity3d[] crv3d, OdGeCurve2d[] crv2d, bool[] orientation3d, bool[] orientation2d, bool makeCopy)
		{
			OdGeCurveBoundary result = new OdGeCurveBoundary(GlobalsPINVOKE.OdGeCurveBoundary_set__SWIG_0(this.swigCPtr, numCurves, crv3d, crv2d, Helpers.MarshalboolFixedArray(orientation3d), Helpers.MarshalboolFixedArray(orientation2d), makeCopy), false);
			if (GlobalsPINVOKE.SWIGPendingException.Pending)
			{
				throw GlobalsPINVOKE.SWIGPendingException.Retrieve();
			}
			return result;
		}

		public OdGeCurveBoundary set(int numCurves, OdGeEntity3d[] crv3d, OdGeCurve2d[] crv2d, bool[] orientation3d, bool[] orientation2d)
		{
			OdGeCurveBoundary result = new OdGeCurveBoundary(GlobalsPINVOKE.OdGeCurveBoundary_set__SWIG_1(this.swigCPtr, numCurves, crv3d, crv2d, Helpers.MarshalboolFixedArray(orientation3d), Helpers.MarshalboolFixedArray(orientation2d)), false);
			if (GlobalsPINVOKE.SWIGPendingException.Pending)
			{
				throw GlobalsPINVOKE.SWIGPendingException.Retrieve();
			}
			return result;
		}

		public bool isOwnerOfCurves()
		{
			bool result = GlobalsPINVOKE.OdGeCurveBoundary_isOwnerOfCurves(this.swigCPtr);
			if (GlobalsPINVOKE.SWIGPendingException.Pending)
			{
				throw GlobalsPINVOKE.SWIGPendingException.Retrieve();
			}
			return result;
		}

		public OdGeCurveBoundary setToOwnCurves()
		{
			OdGeCurveBoundary result = new OdGeCurveBoundary(GlobalsPINVOKE.OdGeCurveBoundary_setToOwnCurves(this.swigCPtr), false);
			if (GlobalsPINVOKE.SWIGPendingException.Pending)
			{
				throw GlobalsPINVOKE.SWIGPendingException.Retrieve();
			}
			return result;
		}

		private object locker = new object();

		private HandleRef swigCPtr;

		protected bool swigCMemOwn;
	}
}
